﻿<?php
//$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
//$rand_keys = array_rand($input,3);
//echo $input[$rand_keys[0]] . "\n";
//exit;
?> 
<?php
	header("Content-Type:text/html;charset=UTF-8");
	require_once 'config.php';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><title>更新商品信息</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src=js/colors.js></script>
<script type="text/javascript" src="scripts/prototype.lite.js"></script>
<script type="text/javascript" src="scripts/moo.fx.js"></script>
<script type="text/javascript" src="scripts/moo.fx.pack.js"></script>
<script type="text/javascript">
function init(){
	var stretchers = document.getElementsByClassName('box');
	var toggles = document.getElementsByClassName('tab');
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: false, height: true, duration: 600}
	);
	//hash functions
	var found = false;
	toggles.each(function(h3, i){
		var div = Element.find(h3, 'nextSibling');
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordion.showThisHideOpen(div);
				found = true;
			}
		});
		if (!found) myAccordion.showThisHideOpen(stretchers[0]);
}
</script>
</head>
<body>
<b>此DEMO的功能:更新商品信息</b>
<p id="msgs" style="height:24px;">
<?php include 'header.php';?>
</p>
  <?php
/* 得到单个商品信息 Start*/
	
	//参数数组
	$paramArr = array(

		/* API系统级输入参数 Start */

	    	'method' => 'taobao.item.get',  //API名称
//		   'session' => $sessions, //session
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */				 

		/* API应用级输入参数 Start*/

	    	'fields' => 'iid,detail_url,num_iid,title,nick,type,cid,seller_cids,props,input_pids,input_str,desc,pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,auto_repost,approve_status,postage_id,product_id,auction_point,property_alias,item_imgs,prop_imgs,skus,outer_id,is_virtual,is_taobao,is_ex,videos,is_3D,score,volume,one_station',  //返回字段
//              'nick' => $userNick,  //卖家昵称
		   'num_iid' => $iid,//商品数字id  
			  
		/* API应用级输入参数 End*/
	);


	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$urls = $url.$strParam;

	$result = vita_get_url_content($urls);

	//解析Xml数据
	$result = getXmlData($result);


/* 得到单个商品信息 End*/	

	
/* 更新商品信息 Start*/	
?>

<form action="ok.php" method="post" enctype="multipart/form-data">
<table border="0" width="80%" align="left">
  <tr>
    <td>店铺类目：</td>
    <td>
  <?php
/* 获取前台展示的店铺内卖家自定义商品类目 Start*/
	
	//参数数组
	$paramArr = array(

		/* API系统级输入参数 Start */

	    	'method' => 'taobao.sellercats.list.get',  //API名称
		   'session' => $sessions, //session
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */				 

		/* API应用级输入参数 Start*/

	    	'fields' => 'iid,detail_url,num_iid,title,nick,type,cid,seller_cids,props,input_pids,input_str,desc,pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,auto_repost,approve_status,postage_id,product_id,auction_point,property_alias,item_imgs,prop_imgs,skus,outer_id,is_virtual,is_taobao,is_ex,videos,is_3D,score,volume,one_station',  //返回字段
//              'nick' => $userNick,  //卖家昵称
		   'nick' => $result['item']['nick'],//商品数字id  
			  
		/* API应用级输入参数 End*/
	);


	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$urls = $url.$strParam;

	$shop = vita_get_url_content($urls);

	//解析Xml数据
	$shop = getXmlData($shop);
	$shop = $shop['seller_cats']['seller_cat'];
	
/* 获取前台展示的店铺内卖家自定义商品类目 End*/	
?>       
	<select name="seller_cids">
    <?php
		foreach ($shop as $key=>$val){
    ?>		
      <option value="<?php echo $val['cid']?>"><?php echo $val['name']?></option>
    <?php }?>
    </select>
	      
    </td>
  </tr>


  <tr>
    <td>商品描述：</td>
    <td align="left">
      <input type="hidden" name="iid" value="<?php  echo $iid?>">
      <textarea id="desc" name="desc" onclick="BodyOnLoad();" style= "width:80%" rows="10"> <?php  echo $result['item']['desc']?></textarea>

    </td>
  </tr>  

  <tr>
    <td>运费模板：</td>
    <td>
          <textarea name="postage_id" id="postage_id" style="display:none"></textarea>
  <?php
/* 获取卖家的运费模板 Start*/
	
	//参数数组
	$paramArr = array(

		/* API系统级输入参数 Start */

	    	'method' => 'taobao.postages.get',  //API名称
		   'session' => $sessions, //session
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */				 

		/* API应用级输入参数 Start*/

	    	'fields' => 'postage_id,name,memo,created,modified,post_price,post_increase,express_price,express_increase,ems_price,ems_increase,postage_modes',  //返回字段
//              'nick' => $userNick,  //卖家昵称

			  
		/* API应用级输入参数 End*/
	);


	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$urls = $url.$strParam;

	$postage = vita_get_url_content($urls);

	//解析Xml数据
	$postage = getXmlData($postage);
	$postage1 = $postage['postages']['postage'];
	$postage2 = $postage['postages']['postage'];

/* 获取卖家的运费模板 End*/	
?>  
<div id="wrapper">
	<div id="content">
	<h3 class="tab" title="请选择模板"><div class="tabtxt"><a href="#">请选择模板</a></div></h3>
    <?php foreach ($postage1 as $postage1=>$post_val1){?>		
	<div class="tab"><h3 class="tabtxt" title="<?php echo $post_val1['name']?>"  onClick="putPostage_id(<?php echo $post_val1['postage_id']?>);">
    <a><?php echo $post_val1['name']?></a></h3></div>      
    <?php }?> 
	<div class="boxholder">
		<div class="box">
			<p>请选择模板</p>
		</div>
    <?php foreach ($postage2 as $postage2=>$post_val2){?>		
		<div class="box">
			<p>最后更新：<?php echo $post_val2['modified']?></p>
<p>平邮收费：<?php echo $post_val2['post_price']?> </p>

<p>平邮加件收费<?php echo $post_val2['post_increase']?> </p>

<p>快递收费： <?php echo $post_val2['express_price']?> </p>

<p>快递加件费用： <?php echo $post_val2['express_increase']?> </p>

<p>EMS收费： <?php echo $post_val2['ems_price']?> </p>

<p>EMS加件费用： <?php echo $post_val2['ems_increase']?> </p>

            
		</div>                
    <?php }?>     
	</div>
</div>
</div>

<script type="text/javascript">
	Element.cleanWhitespace('content');
	init();
function putPostage_id(type){
	document.getElementById("postage_id").innerHTML=type;
}	

</script>
          

    </td>
  </tr>

  <tr>
    <td width="auto">商品属性：</td>
    <td>
	<?php
	$paramArr = array(

		/* API系统级输入参数 Start */

		    'method' => 'taobao.itemprops.get',   //API名称
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */			

		/* API应用级输入参数 Start*/

//			'fields' => 'name,pid,prop_values,is_key_prop',
			'fields' => 'pid,name,is_key_prop,is_sale_prop,is_color_prop,is_enum_prop,is_input_prop,is_item_prop,child_template,must,multi,parent_pid,parent_vid,prop_values,status,sort_order',
	      	   'cid' =>  $result['item']['cid'], //Num_iid
//		       'pid' =>  $result['input_pids'], 
	
		/* API应用级输入参数 End*/	
	);

	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$urls = $url.$strParam;

	//连接超时自动重试
	$cnt=0;	
	while($cnt < 3 && ($itemprops=@vita_get_url_content($urls))===FALSE) $cnt++;
	
	//解析Xml数据
	$itemprops = getXmlData($itemprops);

	$itemprops = $itemprops['item_props']['item_prop'];	
// 	echo '';

		   
	$paramArr = array(

		/* API系统级输入参数 Start */

	    	'method' => 'taobao.itemcats.authorize.get',  //API名称
		   'session' => $sessions, //session
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */				 

		/* API应用级输入参数 Start*/

			'fields' => 'brand.prop_name,brand.pid,brand.vid,brand.name,item_cat.cid,item_cat.name,item_cat.status,item_cat.sort_order,item_cat.parent_cid,item_cat.is_parent',
				
		/* API应用级输入参数 End*/
	);

	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$brand_urls = $url.$strParam;
	
	//连接超时自动重试
	$cnt=0;	
	while($cnt < 3 && ($brand=@vita_get_url_content($brand_urls))===FALSE) $cnt++;
	
	//解析Xml数据
	$brand = getXmlData($brand);

	//返回结果
	$brand = $brand['seller_authorize']['brands']['brand'];
	
    	foreach ($itemprops as $itemprops => $key){
			echo '<font color=green>'.$key['name'].'：</font>';
			$prop_values = $key['prop_values']['prop_value'];

		   		if($key['pid']=='20000'){
					echo '<input type=hidden name="input_pids[]" value="'.$key['pid'].'"><select name="input_str[]">';
		   	
					foreach ($brand as $brand => $key3){
						echo '<option value="'.$key3['name'].'">'.$key3['name'].'</option>'."\n";   
					}	
					echo '</select>';					
				}else{		
		   
			if(is_array($prop_values)){
				echo '<select name="prov[]">';
				foreach ($prop_values as $prop_values => $key2){
					echo '<option value="'.$key['pid'].':'.$key2['vid'].'">'.$key2['name'].'</option>'."\n";
				}
				echo '</select>';
			}else{
				echo '<input type=hidden name="input_pids[]" value="'.$key['pid'].'"><input type=text name="input_str[]">'."\n";	
	
			}}
		echo '<br>';		 
    	}
	?>
    </td>
  </tr>

  <tr>
    <td>
      <input type="submit" name="su" value="更新商品">
    </td>
  </tr>
</table>  
</form>
 
</body>
</html>
